<?php

class Activity_BoardController extends Zend_Controller_Action
{
	public function indexAction()
	{
		// Get the entity informations from the request parameters
		$entityClassIdName = $this->_getParam('entity_class');
		$entityIdName = $this->_getParam('entity_idname');

		// If they can't be found, get them from the current logged in user
		if (empty($entityClassIdName) || empty($entityIdName)) {
			$sessAcc = Account_Model_Session::getAccount();
			if ($sessAcc === NULL) {
				$this->_redirect('/login');
			}
			$entityClassIdName = 'user';
			$entityIdName = $sessAcc->getIdName();
		}


		$entObject = Euso_Object::getInstance($entityClassIdName, NULL, $entityIdName);
		if ($entObject === NULL) {
			throw new Zend_Controller_Action_Exception('Object not found', 404);
		}

		if (isset($entObject)) {
			//TODO: get others' activities for this
			$instances = Activity_Model_Activity::getNewestsByObject($entityClassIdName, $entObject->getId(), 50);

			$activities = array();

			foreach ($instances as $inst) {
				$act = array();
				$subject = $inst->getSubject();
				$entObject = $subject->getObjectInstance();
				$act['transitivity'] = 'transitive';
				$act['subjectNicename'] = $entObject->getNicename();
				$act['subjectUrl'] = site_url_base('/'. $subject->getObjectClassIdName() .'/'. $entObject->getIdName());
				$act['timeRelative'] = time() - date('Z') - $inst->getTime();
				$inst->setParams($act);
			}

			$this->view->activityList = $instances;
		}

		Kernel::getInstance()->setHeadTitle('Activities');

		$this->view->singleWidgetPageTitle = 'Recent Activities';
		$this->view->singleWidgetPage = TRUE;
	}
}